package com.xu.cloud.common.api;

import com.xu.cloud.common.util.DecimalUtil;

import java.math.BigDecimal;
import java.util.Comparator;

/**
 * api version comparator
 *
 * @author xuguan
 * @since 2025/3/11
 */
public class ApiVersionComparator implements Comparator<String> {
    public static final ApiVersionComparator INSTANCE = new ApiVersionComparator();

    @Override
    public int compare(String o1, String o2) {
        return decimalVersion(o1).compareTo(decimalVersion(o2));
    }

    private BigDecimal decimalVersion(String v) {
        v = v.replace("/", "");
        v = v.replace("v", "");
        return DecimalUtil.str2Decimal(v);
    }
}
